﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace MyProblem
{
    public class LengthOfString
    {
        public int LengthOfLongestSubstring(string s)
        {
            //if (s.Length <= 1)
            //    return s.Length;
            //int length = s.Length;
            //int max = 1;
            //for(int i = 0; i < length -1; i++)
            //{
            //    var a = s.Substring(i, 1);
            //    int temp = s.IndexOf(a, i + 1, length - i-1);
            //    if (temp == -1 && length - i > max)
            //        max = length - i;
            //    else if(temp -i > max)
            //    {
            //        max = temp - i;
            //    }
            //}
            int index = 0;
            int max = 1;
            int len = s.Length;
            if (len <= 1)
                return len;
            for (int i = 1; i < len; i++)
            {
                for (int j = i - 1; j >= index; j--)
                {
                    if (s[i] == s[j])
                    {
                        index = j + 1;
                        break;
                    }
                    else
                    {
                        if (max < i - j + 1)
                            max = i - j + 1;
                    }
                }
            }
            return max;
        }
    }
}